package com.orange.entity.sprite;

import com.orange.entity.sprite.vbo.HighPerformanceTexturePackSpriteVertexBufferObject;
import com.orange.entity.sprite.vbo.ITexturePackTiledSpriteVertexBufferObject;
import com.orange.opengl.shader.PositionColorTextureCoordinatesShaderProgram;
import com.orange.opengl.shader.ShaderProgram;
import com.orange.opengl.vbo.DrawType;
import com.orange.opengl.vbo.VertexBufferObjectManager;
import com.orange.res.RegionRes;
import com.orange.util.texturepack.ITiledTexturePackTextureRegion;

public class TexturePackSprite extends AnimatedSprite {

	public TexturePackSprite(float pX, float pY, String pTextureRegionName, VertexBufferObjectManager pVertexBufferObjectManager) {
		this(pX, pY, RegionRes.getRegion(pTextureRegionName), pVertexBufferObjectManager);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, String pTextureRegionName, VertexBufferObjectManager pVertexBufferObjectManager) {
		this(pX, pY, pWidth, pHeight, RegionRes.getRegion(pTextureRegionName), pVertexBufferObjectManager);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, ITexturePackTiledSpriteVertexBufferObject pTexturePackTiledSpriteVertexBufferObject) {
		this(pX, pY, pWidth, pHeight, pTiledTexturePackTextureRegion, pTexturePackTiledSpriteVertexBufferObject, PositionColorTextureCoordinatesShaderProgram.getInstance());
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, DrawType pDrawType, ShaderProgram pShaderProgram) {
		this(pX, pY, pWidth, pHeight, pTiledTexturePackTextureRegion, new HighPerformanceTexturePackSpriteVertexBufferObject(pVertexBufferObjectManager, TiledSprite.TILEDSPRITE_SIZE * pTiledTexturePackTextureRegion.getTileCount(), pDrawType, true, Sprite.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT), pShaderProgram);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, DrawType pDrawType) {
		this(pX, pY, pWidth, pHeight, pTiledTexturePackTextureRegion, new HighPerformanceTexturePackSpriteVertexBufferObject(pVertexBufferObjectManager, TiledSprite.TILEDSPRITE_SIZE * pTiledTexturePackTextureRegion.getTileCount(), pDrawType, true, Sprite.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, ShaderProgram pShaderProgram) {
		this(pX, pY, pWidth, pHeight, pTiledTexturePackTextureRegion, pVertexBufferObjectManager, DrawType.STATIC, pShaderProgram);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager) {
		this(pX, pY, pWidth, pHeight, pTiledTexturePackTextureRegion, pVertexBufferObjectManager, DrawType.STATIC);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager) {
		this(pX, pY, pTiledTexturePackTextureRegion, pVertexBufferObjectManager, DrawType.STATIC);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, DrawType pDrawType) {
		this(pX, pY, pTiledTexturePackTextureRegion.getSourceWidth(), pTiledTexturePackTextureRegion.getSourceHeight(), pTiledTexturePackTextureRegion, pVertexBufferObjectManager, pDrawType);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, ShaderProgram pShaderProgram) {
		this(pX, pY, pTiledTexturePackTextureRegion, pVertexBufferObjectManager, DrawType.STATIC, pShaderProgram);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, ITexturePackTiledSpriteVertexBufferObject pTexturePackTiledSpriteVertexBufferObject) {
		this(pX, pY, pTiledTexturePackTextureRegion, pTexturePackTiledSpriteVertexBufferObject, PositionColorTextureCoordinatesShaderProgram.getInstance());
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager, DrawType pDrawType, ShaderProgram pShaderProgram) {
		this(pX, pY, pTiledTexturePackTextureRegion, new HighPerformanceTexturePackSpriteVertexBufferObject(pVertexBufferObjectManager, TiledSprite.TILEDSPRITE_SIZE * pTiledTexturePackTextureRegion.getTileCount(), pDrawType, true, Sprite.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT), pShaderProgram);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, ITexturePackTiledSpriteVertexBufferObject pTexturePackTiledSpriteVertexBufferObject, ShaderProgram pShaderProgram) {
		this(pX, pY, pTiledTexturePackTextureRegion.getSourceWidth(), pTiledTexturePackTextureRegion.getSourceHeight(), pTiledTexturePackTextureRegion, pTexturePackTiledSpriteVertexBufferObject, pShaderProgram);
		// TODO Auto-generated constructor stub
	}

	public TexturePackSprite(float pX, float pY, float pWidth, float pHeight, ITiledTexturePackTextureRegion pTiledTexturePackTextureRegion, ITexturePackTiledSpriteVertexBufferObject pTexturePackTiledSpriteVertexBufferObject, ShaderProgram pShaderProgram) {
		super(pX, pY, pWidth, pHeight, pTiledTexturePackTextureRegion, pTexturePackTiledSpriteVertexBufferObject, pShaderProgram);
		// TODO Auto-generated constructor stub
	}
	
	
	public void setFlippedHorizontal(final boolean pFlippedHorizontal) {
		//要做判断，提高效率，同时也要先super到父类再onUpdateVertices，才能实现更新定点的效果
		if(this.mFlippedHorizontal != pFlippedHorizontal) {
			super.setFlippedHorizontal(pFlippedHorizontal);
			this.onUpdateVertices();
		}else {
			super.setFlippedHorizontal(pFlippedHorizontal);
		}
	}

	
	public void setFlippedVertical(final boolean pFlippedVertical) {
		//要做判断，提高效率，同时也要先super到父类再onUpdateVertices，才能实现更新定点的效果
		if(this.mFlippedVertical != pFlippedVertical) {
			super.setFlippedVertical(pFlippedVertical);
			this.onUpdateVertices();
		}else {
			super.setFlippedVertical(pFlippedVertical);
		}
	}

	
	public void setFlipped(final boolean pFlippedHorizontal, final boolean pFlippedVertical) {
		//要做判断，提高效率，同时也要先super到父类再onUpdateVertices，才能实现更新定点的效果
		if((this.mFlippedHorizontal != pFlippedHorizontal) || (this.mFlippedVertical != pFlippedVertical)) {
			super.setFlipped(pFlippedHorizontal, pFlippedVertical);
			this.onUpdateVertices();
		}else {
			super.setFlipped(pFlippedHorizontal, pFlippedVertical);
		}
	}
	
	
	protected void onUpdateVertices() {
		this.getVertexBufferObject().onUpdateVertices(this);
	}
	
	
	public ITexturePackTiledSpriteVertexBufferObject getVertexBufferObject() {
		return (ITexturePackTiledSpriteVertexBufferObject) super.getVertexBufferObject();
	}
	
	public ITiledTexturePackTextureRegion getTiledTextureRegion() {
		return (ITiledTexturePackTextureRegion) this.mTextureRegion;
	}
	
}
